import os

from django.shortcuts import render
# Create your tests here.
from mongoengine import QuerySet

from academic import settings
from authorshow.models.models import Author


def test(request):
    author: QuerySet = Author.objects(name='Xia Jianjun')
    first_author = author.first()
    id = first_author.id

    # update.update_icon(id=id, file_path='D:\\img\\icon.jpg')
    # 使用 .icon.read() 获取到文件
    file_path = "/academic/icon/" + id + ".jpg"
    first_author.icon = settings.ICON_URL + id + ".jpg"
    first_author.save()
    print(os.path.abspath(file_path))
    # first_author.icon = fw
    # first_author.save()

    # f.write(icon)
    # f.close()
    return render(request=request, template_name='test.html')
